package com.xyebank.ledger.service.nx.adaper;

import org.modelmapper.ModelMapper;
import org.modelmapper.PropertyMap;
import org.springframework.stereotype.Component;

import com.xyebank.ledger.db.entitys.LRepaymentInf;
import com.xyebank.ledger.service.common.conveter.RePayBeanConverter;
import com.xyebank.ledger.service.constant.CommonConstant;
import com.xyebank.ledger.service.constant.ProductConstant;
import com.xyebank.ledger.util.IDUtil;
import com.xyebank.ledger.util.StatusConvertUtil;
import com.xyebank.ledger.vo.deal.LNxCashRepaymentInfoVo;

@Component(value = "nXRepaymentBeanConverter")
public class NXRepaymentBeanConverter implements RePayBeanConverter<LNxCashRepaymentInfoVo> {
    
    
    ModelMapper modelMapper = new ModelMapper();

    class NXRepaymentPropertyMap extends PropertyMap<LNxCashRepaymentInfoVo, LRepaymentInf> {
        protected void configure() { 
            map(source.getMblNo(), destination.getMblNo());
        	map(source.getOrdNo(), destination.getXyOrderNo());
        	map(source.getThreePartyOrdNo(), destination.getOrgOrderNo());
        	map(source.getCashAmount(), destination.getCashAmount());
        	map(source.getPayInterest(), destination.getPayInterest());
        	map(source.getPayPrincipal(), destination.getPayPrincipal());
        	map(source.getPayServerFee(), destination.getPayServerFee());
        	map(source.getPayLateFee(), destination.getPayLateFee());
        	map(source.getPayPenalty(), destination.getPayPenalty());
        	map(source.getRepayAmount(), destination.getRepayAmount());
        	map(source.getRepayTime(), destination.getRepayTime());
        }
    }

    public NXRepaymentBeanConverter() {
        modelMapper.addMappings(new NXRepaymentPropertyMap());
    }

    @Override
    public LRepaymentInf covert(LNxCashRepaymentInfoVo x) {
    	LRepaymentInf entity = modelMapper.map(x, LRepaymentInf.class);
        entity.setId(IDUtil.generateId(x.getId().toString(), "nx"));
        entity.setDataSource(x.getSubOrgNo().equals("01") ? CommonConstant.JRY_STR : CommonConstant.SJD_STR);
        entity.setXyProductNo(ProductConstant.NX_LOAN_PROD_ID);
        entity.setXyOrgNo(ProductConstant.NX_LOAN_ORG);
        if(x.getStatus() != null) entity.setStatus(StatusConvertUtil.convertRepayStatus(x.getStatus()));
        return entity;
    }
}
